<template>
<!--  100材料详情列表-->
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="专业包代码" name="majorCode" slot="advanced" />
        <f-search-form-item label="专业包名称" name="majorName"/>
        <f-search-form-item label="工程包代码" name="packageNo" slot="advanced" />
        <f-search-form-item label="工程包名称" name="packageName"/>
        <f-search-form-item label="材料WBS" name="materialWbsCode" slot="advanced" />
        <f-search-form-item label="材料代码" name="materialCode" slot="advanced" />
<!--        <f-search-form-item label="设备材料名称&#45;&#45;无此字段" name="packageNo"/>-->
        <f-search-form-item label="层级号" name="levelNo" slot="advanced" />
        <f-search-form-item label="科目名称" name="subjectName" slot="advanced" />
<!--        <f-search-form-item label="项目&#45;&#45;无此字段" name="packageNo"/>-->
        <f-search-form-item label="区域" name="materialArea" slot="advanced" />
        <f-search-form-item label="系统" name="materialUse" slot="advanced" />
        <f-search-form-item label="历史版本" name="versionId"  type="select" ref="versionData" :showAll="true" :autoLoad="true" :data="api.bmep.selectVersionList" labelKey="versionNo" valueKey="versionId" slot="advanced"   />
        <f-search-form-item label="履历筛选" name="planType" type="select" :data="hDataDemo" slot="advanced"  @change="typeChange"  ></f-search-form-item>
      </f-search-form>
      <f-table ref="table" rowKey="materialPlanId" :scroll="{x:200,y:columns.length*35}" :columns="columns" :exportBtn="false" :multiple="false" :operator="operator" :params="queryParam" :api="api.bmep" handler="materialPlanPageListHandler">
      </f-table>
      <bmp-update-drawer ref="updateDrawer" :listType="listType"></bmp-update-drawer>
    </a-card>
  </div>
</template>
<script>
  import bmpUpdateDrawer from './bmp_update_drawer.vue'
  import api from './js/api'
  export default {
    name: 'TableList',
    components: {
      bmpUpdateDrawer
    },
    props: {
      // versionId: {
      //   type: String,
      //   default: ''
      // },
      projectId: {
        type: String,
        default: ''
      },
      projectStatus: {
        type: String,
        default: ''
     }
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      // operator.push({
      //   name: '提交',
      //   icon: '',
      //   that: this,
      //   handler: function(table, that) {
      //       // that.$refs.draw.ershowDrawer
      //     that.merge100()
      //   }
      // })
      operator.push({
        name: '修正变更',
        icon: '',
        that: this,
        handler: function(table, that) {
          if (that.projectStatus === 1){
            that.$message.error('项目已锁定不支持操作')
            return
          }
          let pars = table.parameter
          that.http.post(that, {
            url: that.api.bmep.buttonStatus,
            data: {
              projectId :that.queryParam.projectId,
              versionType: '100'
            },
            success: function(me,data) {
              if(data.buttonStatus === 1){
                that.listType = 1
                that.$refs.updateDrawer.showDrawer(1,pars)
              }else{
                that.$message.error('当前材料版本不支持修改计划')
              }
            }
          })
        }
      })
      operator.push({
        name: '追加变更',
        icon: '',
        that: this,
        handler: function(table, that) {
          if (that.projectStatus === 1){
            that.$message.error('项目已锁定不支持操作')
            return
          }
          let pars = table.parameter
          that.http.post(that, {
            url: that.api.bmep.buttonStatus,
            data: {
              projectId : that.queryParam.projectId,
              versionType: '100'
            },
            success: function(me,data) {
              if(data.buttonStatus === 1){
                that.listType = 2
                that.$refs.updateDrawer.showDrawer(2,pars)
              }else{
                that.$message.error('当前材料版本不支持追加变更')
              }
            }
          })
        }
      })
      operator.push({
        name: '转存200',
        icon: '',
        that: this,
        handler: function(table, that) {
          that.zc200Submit()
        }
      })
      return {
        api:  Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {
          projectId: me.projectId
          // versionId: me.versionId
        },
        buttonStatus: '',
        hDataDemo: [{ label: '修正变更', value: 1 }, { label: '追加变更', value: 2 }],
        listType: 1, // 1 修正计划  追加变更
        // 表头
        columns: [
          {
            title: '序号',
            align: 'center',
            width: 60,
            customRender: (text, record, index) => index + 1
          },
          {
            title: '专业代码',
            align: 'center',
            width: 100,
            dataIndex: 'majorCode'
          },
          {
            title: '专业名称',
            align: 'center',
            width: 120,
            dataIndex: 'majorName'
          },
          {
            title: '工程包名称',
            align: 'center',
            width: 120,
            dataIndex: 'packageName'
          },
          {
            title: '工程包代码',
            align: 'center',
            width: 120,
            dataIndex: 'packageNo'
          },
          {
            title: '材料WBS代码',
            align: 'center',
            width: 130,
            dataIndex: 'materialWbsCode'
          },
          {
            title: '全物料代码',
            align: 'center',
            width: 120,
            dataIndex: 'materialCode'
          },
          // {
          //   title: '设备、材料名称',
          //   align: 'center',
          //   width: 200,
          //   dataIndex: 'materialName'
          // },
          // {
          //   title: '型号/规格',
          //   align: 'center',
          //   width: 200,
          //   dataIndex: 'materiaSpecs'
          // },
          // {
          //   title: '项目名称',
          //   align: 'center',
          //   width: 200,
          //   dataIndex: 'materiaSpecs'
          // },
          // {
          //   title: '材料项目描述',
          //   align: 'center',
          //   width: 200,
          //   dataIndex: 'materialDesc'
          // },
          // {
          //   title: '技术参数或技术说明',
          //   align: 'center',
          //   width: 200,
          //   dataIndex: 'technicalData'
          // },
          // {
          //   title: '科目名称',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'subjectName'
          // },
          {
            title: '层级号',
            align: 'center',
            width: 60,
            dataIndex: 'levelNo'
          },
          // {
          //   title: '项目',
          //   align: 'center',
          //   width: 100,
          //   dataIndex: 'subjectName'
          // },
          {
            title: '对外合同描述',
            align: 'center',
            width: 150,
            dataIndex: 'contractDesc'
          },
          {
            title: '区域',
            align: 'center',
            width: 60,
            dataIndex: 'materialArea'
          },
          {
            title: '系统',
            align: 'center',
            width: 60,
            dataIndex: 'materialUse'
          },
          {
            title: '标前工程量',
            align: 'center',
            width: 100,
            dataIndex: 'beforeMarkQuantity'
          },
          {
            title: '100预算成本工程量',
            align: 'center',
            width: 150,
            dataIndex: 'costQuantity100'
          },
          {
            title: '损耗',
            align: 'center',
            width: 60,
            dataIndex: 'loss'
          },
          {
            title: '计量单位',
            align: 'center',
            width: 80,
            dataIndex: 'measurementUnit'
          },
          {
            title: '100采购计划量',
            align: 'center',
            width: 120,
            dataIndex: 'planPurchaseCount'
          },
          {
            title: '审批状态',
            align: 'center',
            width: 120,
            dataIndex: 'applayStatus',
            customRender: function (text) {
              return me.columnFormatter(me.api.bmep.applayStatus, text)
            }
          }
          // {
          //   title: '有合同主材单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractInstallPrice1'
          // },
          // {
          //   title: '拟合同主材单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractInstallPrice2'
          // },
          // {
          //   title: '合同主材单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractInstallPrice3'
          // },
          // {
          //   title: '有合同其他单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractOtherPrice1'
          // },
          // {
          //   title: '拟合同其他单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractOtherPrice2'
          // },
          // {
          //   title: '合同其他单价',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'contractOtherPrice3'
          // }
          // ,
          // {
          //   title: '添加时间',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'createTime'
          // },
          // {
          //   title: '更新时间',
          //   width: '100',
          //   align: 'center',
          //   dataIndex: 'updateTime'
          // }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      zc200Submit() {
        if (this.projectStatus === 1){
          this.$message.error('项目已锁定不支持操作')
          return
        }
        let selectIds = this.$refs.table.getSelectedRowKey()
        // if (!selectIds || selectIds.length === 0) {
        //   this.$message.error('您还未选中数据')
        //   return
        // }
        this.http.post(this, {
          url: this.api.bmep.zc200,
          data: {
            materialPlanIds: selectIds.join(','),
            projectId : this.queryParam.projectId
          },
          success: function(me) {
            me.$refs.table.refresh(true)
          }
        })
      },
      merge100() {
        if (this.projectStatus === 1){
          this.$message.error('项目已锁定不支持操作')
          return
        }
        let that = this
        that.http.post(that, {
          url: that.api.bmep.margeplan100,
          data: {
            projectId : this.queryParam.projectId
          },
          success(me, data) {
            me.$message.success('合并成功')
          }
        })
      },
      typeChange(val) {
        this.detailsParams.versionType = val
        this.refs.versionData.initData(this.queryParam)
      }
    }
  }
</script>
<style>


</style>
